package com.xd.springboot.controller;

import com.alibaba.fastjson.JSON;
import com.xd.springboot.entity.User;
import com.xd.springboot.service.RedisService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/redis")
public class RedisController {

    private  static  final Logger log=LoggerFactory.getLogger(RedisController.class);

    @Resource
    private RedisService redisService;

    @GetMapping("/add")
    public  String TestSet()
    {
        redisService.setString("weichat","程序员私房菜");
        return "success";
    }

    @GetMapping("/adduser")
    public  String TestUser()
    {
        User user = new User(1234L,"admin","88888888");
        redisService.setString("userInfo", JSON.toJSONString(user));
        return "success";
    }

    @GetMapping("/addhash")
    public  String TestHash()
    {
        User user = new User(1234L,"admin","88888888");
        redisService.setHash("userInfo",user.getUsername(), JSON.toJSONString(user));
        return "success";
    }

    @GetMapping("/get")
    public  String TestGet()
    {

        log.info("我的微信公众号为：{}", redisService.getString("weichat"));
        return "success";
    }

    @GetMapping("/addlist")
    public  void TestList()
    {
        redisService.setList("list","aaaa");
        redisService.setList("list","fsdfsdfs");
    }
}
